package math;

/*
 *@description 加一
 *@author hkfan
 *@version 1.0
 *@create 2025/6/18 16:04
 */
public class LeetCode_66 {

    public int[] plusOne(int[] digits) {
        boolean flag = true;
        for (int i = digits.length-1; i>=0; i--) {
            if (flag){
                digits[i]+=1;
                flag=false;
            }
            if (digits[i]>=10){
                digits[i]-=10;
                flag=true;
            }
        }
        if (flag){
            int[] res = new int[digits.length + 1];
            res[0]=1;
            for (int i = 0; i < digits.length; i++) {
                res[i+1]=digits[i];
            }
            return res;
        }
        return digits;
    }
}
